package com.dense.kuiniu.floatcabinet.mvp.ui.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ScreenUtils;
import com.dense.kuiniu.floatcabinet.R;
import com.dense.kuiniu.floatcabinet.utils.timer.CountDownView;
import com.dense.kuiniu.floatcabinet.utils.timer.CounterController;

/**
 * @author Administrator
 * @date 2020/10/28
 */
public class DialogOpenDoor extends Dialog {
    public DialogOpenDoor(@NonNull Context context) {
        super(context);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_open_door, null);
        CountDownView countDownView = view.findViewById(R.id.view_count_down);
        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        countDownView.start(new CounterController.OnCompleteListener() {
            @Override
            public void onComplete() {
                dismiss();
            }
        });
        setContentView(view);
    }

    @Override
    public void show() {
        super.show();
        measureSize();
    }

    protected void measureSize() {
        Window dialogWindow = getWindow();
        if (dialogWindow != null) {
            dialogWindow.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.shape_transparent));
            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
            lp.width = (int) (ScreenUtils.getScreenWidth() * 0.65); // 宽度
            lp.height = (int) (ScreenUtils.getScreenHeight() * 0.315); // 高度
            dialogWindow.setGravity(Gravity.CENTER);
            dialogWindow.setAttributes(lp);
            dialogWindow.setWindowAnimations(R.style.DialogOutAndInStyle);
        }
    }

    public interface OnOpenListener {
        void onOpen();
    }

}